cmake_minimum_required(VERSION 3.10)

set(component_name WString)
set(component_type SHARED) # STATIC or SHARED or INTERFACE
# 设置权限范围变量
set(component_scope PUBLIC) # PUBLIC or PRIVATE or INTERFACE

# project(${component_name})
add_library(${component_name} ${component_type})

# Enable CMake support for ASM and C languages
enable_language(C CXX ASM)

target_compile_definitions(${component_name} ${component_scope}

)

### Set compile directories
set(COMPILE_DIR 
    ${CMAKE_CURRENT_LIST_DIR}
)

### Get source file
set(SOURCES)
set(HEADER_DIRS)
# 遍历 COMPILE_DIR 中的每一个目录，获取源文件与头文件路径
foreach(dir IN LISTS COMPILE_DIR)
    file(GLOB_RECURSE temp_sources 
        ${dir}/*.c 
        ${dir}/*.cc 
        ${dir}/*.cpp 
        # ${dir}/*.s 
        # ${dir}/*.S
    )
    list(APPEND SOURCES ${temp_sources})  # 将临时源文件添加到 SOURCES

    file(GLOB_RECURSE temp_header_files 
        ${dir}/*.h
        ${dir}/*.hpp
        ${dir}/*.hxx
    )
    foreach(header_file ${temp_header_files})
        get_filename_component(header_dir ${header_file} DIRECTORY)
        list(APPEND HEADER_DIRS ${header_dir})  # 将头文件目录添加到 HEADER_DIRS
    endforeach()
endforeach()

### Remove duplicate directories
list(REMOVE_DUPLICATES SOURCES)      # 去除重复的源文件
list(REMOVE_DUPLICATES HEADER_DIRS)  # 去除重复的头文件目录

# message("SOURCES: ${SOURCES}\n")
message("HEADER_DIRS: ${HEADER_DIRS}\n")

target_sources(${component_name} ${component_scope}
    ${SOURCES}
)

target_include_directories(${component_name} ${component_scope}
    ${HEADER_DIRS}
)

target_link_directories(${component_name} ${component_scope}

)

target_link_libraries(${component_name} ${component_scope}

)

# Validate that ${component_name} code is compatible with C standard
# if(CMAKE_C_STANDARD LESS 11)
#     message(ERROR "Generated code requires C11 or higher")
# endif()


